/*
 * 描          述:  <描述>
 * 修  改   人:  PengQingyang
 * 修改时间:  2022年6月22日
 * <修改描述:>
 */
package com.tx.component.file.configurator;

import com.aliyun.oss.OSS;
import com.tx.component.file.resource.FCResourceLoader;
import com.tx.component.file.resource.impl.AliyunOSSFCResourceLoader;
import com.tx.component.file.resource.impl.LocalAwareFCResourceLoader;
import com.tx.core.exceptions.util.AssertUtils;

/**
 * 本地文件目录工厂
 * <功能详细描述>
 * 
 * @author  PengQingyang
 * @version  [版本号, 2022年6月22日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class AliyunOSSFCResourceLoaderBuilder extends FCResourceLoaderBuilder {
    
    /**
     * 创建VFSFCResource的工厂类<br/>
     * <功能详细描述>
     * @return [参数说明]
     * 
     * @return VFSFCResourceFactory [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    public static AliyunOSSFCResourceLoaderBuilder newInstance() {
        AliyunOSSFCResourceLoaderBuilder factory = new AliyunOSSFCResourceLoaderBuilder();
        return factory;
    }
    
    /** 路径 */
    private String localPath = null;
    
    /** 是否本地注入 */
    private boolean localAware = false;
    
    /** 路径 */
    private OSS ossClient = null;
    
    /** 路径 */
    private String bucketName = null;
    
    /** <默认构造函数> */
    AliyunOSSFCResourceLoaderBuilder() {
        super();
    }
    
    /**
     * @return
     */
    @Override
    public FCResourceLoader build() {
        AssertUtils.notEmpty(this.catalog, "catalog is empty.");
        AssertUtils.notEmpty(this.bucketName, "bucketName is empty.");
        AssertUtils.notNull(this.ossClient, "ossClient is null.");
        
        if (this.localAware) {
            AssertUtils.notEmpty(this.localPath, "localPath is empty.");
            
            AliyunOSSFCResourceLoader ossResourceLoader = new AliyunOSSFCResourceLoader(
                    ossClient, bucketName);
            ossResourceLoader.afterPropertiesSet();
            
            LocalAwareFCResourceLoader loader = new LocalAwareFCResourceLoader(
                    catalog, this.localPath, ossResourceLoader);
            return loader;
        } else {
            AliyunOSSFCResourceLoader loader = new AliyunOSSFCResourceLoader(
                    ossClient, bucketName);
            return loader;
        }
    }
    
    /**
     * @param 对localAware进行赋值
     */
    public AliyunOSSFCResourceLoaderBuilder localAware(boolean localAware) {
        this.localAware = localAware;
        return this;
    }
    
    /**
     * @param 对localPath进行赋值
     */
    public AliyunOSSFCResourceLoaderBuilder localPath(String localPath) {
        this.localPath = localPath;
        return this;
    }
    
    /**
     * @param 对ossClient进行赋值
     */
    public AliyunOSSFCResourceLoaderBuilder ossClient(OSS ossClient) {
        this.ossClient = ossClient;
        return this;
    }
    
    /**
     * @param 对bucketName进行赋值
     */
    public AliyunOSSFCResourceLoaderBuilder bucketName(String bucketName) {
        this.bucketName = bucketName;
        return this;
    }
}
